home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 273_01 / parsefn.cc < prev    next >
Text File  |  1987-09-26  |  1KB  |  54 lines

  1. parse_fn(char *fspec,char *fdrive, char *fpath, char *fn, char *fe)
  2. /* This function will parse and break apart the filespec pointed to
  3.    by *fspec.    It will pass back the drive, directory, filename, extension.
  4.    If a given part does not exist a NULL character string will be passed
  5.    back.
  6. */
  7. {
  8.         char work[85], *fpt, ch;
  9.         int slash_found=0;
  10.     *fpath=0x00; *fn=0x00; *fe=0x00;
  11.     *fdrive=0x00;
  12.     strcpy(work,fspec);
  13.     if(work[1]==':') {
  14.         toupper(work[0]);
  15.         *fdrive=work[0];
  16.         strcpy(&work[0],&work[2]);
  17.         }
  18.     fpt=work + strlen(work) - 1;
  19.     while(fpt >= work) {
  20.        if(*fpt=='.') {
  21.             strcpy(fe,fpt+1);
  22.             *fpt=0x00;
  23.             fpt--;
  24.        }
  25.        else {
  26.                if(*fpt=='\\') {
  27.                    slash_found++;
  28.                    if(slash_found==1) {
  29.                        strcpy(fn,fpt+1);
  30.                        *fpt=0x00;
  31.                        fpt--;
  32.                    }
  33.                    else
  34.                    if(fpt==work) {
  35.                        strcpy(fpath,fpt);
  36.                        fpt--;
  37.                    }
  38.                    else
  39.                        fpt--;
  40.                }
  41.                else
  42.                    fpt--;
  43.                 }
  44.     }
  45.  
  46.     if(slash_found==1)
  47.         strcpy(fpath,"\\");
  48.     if(slash_found==0)
  49.         strcpy(fn,work);
  50.     upcase(fpath);
  51.     upcase(fn);
  52.     upcase(fe);
  53. }
  54.